﻿
@using System.Data;
@using Shop.Entity;
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
}
@model  PagedList<DataRow>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>列表</title>
    <link href="~/Content/admin/css/bootstrap.min.css" rel="stylesheet" />

    <script src="/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/admin/js/bootstrap.min.js"></script>
    <script src="~/Content/MvcPager/MvcPager.js"></script>
</head>
<body>
    <div class="container-fluid">
        <ol class="breadcrumb">
            <li><a href="/set/admin/center">首页></a></li>
            <li><a href="#">积分换礼></a></li>
            <li class="active">礼品类别</li>
        </ol><div class="navbar-form navbar-left" role="search" style="padding:0px;">
            <a class="btn btn-primary btn-sm" onclick="Add();"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增</a>
        </div>
        <form class="navbar-form navbar-left" id="formSearch" role="form" method="post">
            <div class="form-group">
                <input type="text" class="form-control input-sm" id="SearchTitle" name="title" placeholder="请输入分类名称" />
            </div>
            <button type="submit" class="btn btn-primary btn-sm ">
                <span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>&nbsp;搜索
            </button>
        </form>
        <div class="portlet-body">

            <div id="divTable">
                <table class="table table-bordered  table-condensed table-condensed  table-condensed table-hover" id="treeTable1">
                    <thead>
                        <tr>
                            <th>类别名称</th>
                            <th>显示顺序</th>
                            <th>备注</th>
                            <th>添加时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var row in Model)
                        {
                        <tr>
                            <td class="title"> @row["Title"]</td>
                            <td>@row["Sort"]</td>
                            <td>@row["Remark"] </td>
                            <td>@Convert.ToDateTime(row["AddTime"]).ToString("yyyy-MM-dd HH:MM:ss")</td>
                            <td>
                                <a title="编辑" class="btn  btn-default btn-xs" data-ajax="true" onclick="Edit('@row["Guid"]','@row["Title"]','@row["Sort"]','@row["Remark"]');"> 编辑 </a>
                                <a class="btn btn-default btn-xs" title='删除' onclick="Delete('@row["Guid"]','@row["Title"]' )">删除</a>
                            </td>
                        </tr>
                        }
                    </tbody>
                </table>
                <div class="text-left">
                    <ul class="pagination">
                        <li>
                            <span aria-hidden="true">
                                @(Model.PageSize)条/页，@(Model.TotalPageCount)页, 共@(Model.TotalItemCount)条
                            </span>
                        </li>

                        <li>
                            <span aria-hidden="true">
                                每页
                                <select style="border-radius:4px;font-family:normal;vertical-align: text-bottom;" id="PageSize" name="PageSize" onchange="PageSizeChange();">
                                    <option value="10">10</option>
                                    <option value="15">15</option>
                                    <option value="20">20</option>
                                </select>
                                条
                            </span>
                        </li>
                    </ul>
                    @Ajax.Pager(Model,
new PagerOptions
{
    PageIndexParameterName = "id",
    CssClass = "pagination",
    FirstPageText = "首页",
    LastPageText = "尾页",
    PrevPageText = "上一页",
    PageIndexBoxId = "pageIndexBox",
    NextPageText = "下一页",
    CurrentPagerItemTemplate = "<li class=\"active\"><a data-pageindex=\"{0}\" href=\"/articleinfo/articlecategory/list/{0}\">{0}</a></li>",
    DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
    PagerItemTemplate = "<li>{0}</li>",
    AutoHide = false,

}, new MvcAjaxOptions
{
    UpdateTargetId = "divTable",
    HttpMethod = "Post",
    DataFormId = "formSearch",
    EnableHistorySupport = false,
    EnablePartialLoading = true
    //OnSuccess = "EditMsg",
}
)
                    <ul class="pagination" style="width:20%;margin-top: 0px;">
                        <li>
                            <div class="input-group">
                                <span class="input-group-addon" id="sizing-addon2">跳转到第</span>
                                <input type="text" id="pageIndexBox" value="@Model.CurrentPageIndex" class="form-control input-sm" placeholder="" aria-describedby="sizing-addon2">
                                <span class="input-group-btn">
                                    <button class="btn btn-primary btn-sm" type="button">Go</button>
                                </span>
                            </div>
                        </li>
                    </ul>
                </div>

                <script type="text/javascript">
                    var txt = $("#SearchTitle").val().trim();
                    if (txt.length > 0) {
                        $(".title").each(function () {
                            var newTxt = $(this).html().replace(txt, txt.fontcolor("red"));
                            $(this).html(newTxt);
                        });
                    }
                </script>
                @{Html.RegisterMvcPagerScriptResource();}
            </div>

            <div id="divAdd">
                @Html.Partial("_Add", new TGiftCategory())
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function Add(data)
        {

            $("#add").find("input").not(".btn").each(function ()
            {
                $(this).val("");
            });
            $("#Remark").val("");
            $(this).removeData('modal');
            $("#Add").modal('show');
            $("#Title").focus();
        }
        function Edit(Guid, Title, Sort, Remark)
        {
            $("#headerTitle").text("编辑礼品分类-" + Title);
            $("#Guid").val(Guid); $("#Remark").val(Remark);
            $("#Title").val(Title);
            $("#Sort").val(Sort);
            $(this).removeData('modal');
            $("#Add").modal('show');
            $("#Title").focus();
        }
        function Delete(obj, title)
        {
            parent.layer.confirm('确定要删除【' + title + '】吗?', {
                title: "提示", icon: 3,
                btn: ['确定', '取消'] //按钮
            }, function ()
            {
                $.post("/ArticleInfo/ArticleCategory/delete", { id: obj }, function (data)
                {
                    parent.layer.closeAll('dialog'); //关闭信息框
                    if (data.succ)
                    {
                        $("#formSearch").submit();
                        //  window.location.reload();
                    } else
                    {
                        parent.layer.alert(data.msg, { title: "提示", icon: 5, time: 5000 });
                    }

                })
            }, function () { });
        }
    </script>
</body>
</html>
